package framework.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.servlet.ModelAndView;

/**
 * 保存一些ViewController ,即需要有jsp页面显示的Controller
 *
 * @author WeiJianXing
 * @time 2014-5-21 上午7:55:46
 */
public abstract class BaseViewController {


    protected String redirect(String action) {
        return "redirect:" + action;
    }

    protected ModelAndView JspLocation(ModelAndView modelAndView, String action) {
        modelAndView.setViewName(getJspLocation() + action);
        return modelAndView;
    }

    protected String JspLocation(String action) {
        return getJspLocation() + action;
    }

    /**
     * 格式如下: format /jspdir/
     *
     * @return jsp文件所在目录
     */
    protected abstract String getJspLocation();


    protected Subject getSubject() {
        Subject subject = SecurityUtils.getSubject();

        if (subject != null) {
            return subject;
        }
        throw new NullPointerException("No subject");
    }
}
